using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Microsoft.MediaCenter;
using Microsoft.MediaCenter.UI;

namespace MCEMediaManager
{
    public enum MediaItemType { TV, Movie, Music, Video, Picture, AudioBook, Unknown }
    public interface IMediaItem : IModelItem
    {
        Uri URL{get;set;}
        string Name {get;set;}
        MediaItemType Type {get;set;}
        string Genre {get;set;}
        IMediaPlugin Plugin { get;set;}
        string ListDisplayName { get;set; }
        string ListDisplayDescription { get; }
        string ListDisplayProperties { get; }
        ArrayListDataSet Commands { get;set;}
        ArrayListDataSet RatingsCommands { get; }
        Single AvgRating { get; set; }
        Single UserRating { get; set; }
    }

    public class MediaItem : ModelItem, IMediaItem
    {
        private Uri _URL;

        public Uri URL
        {
            get { return (this._URL); }
            set 
            {
                if (this._URL != value)
                {
                    this._URL = value;
                    FirePropertyChanged("URL");
                }
            }
        }

        private string _Name;

        public string Name
        {
            get { return (this._Name); }
            set 
            {
                if (this._Name != value)
                {
                    this._Name = value;
                    FirePropertyChanged("Name");
                }
            }
        }

        private string _Genre;

        public string Genre
        {
            get { return (this._Genre); }
            set 
            {
                if (this._Genre != value)
                {
                    this._Genre = value;
                    FirePropertyChanged("Genre");
                }
            }
        }

        private MediaItemType _Type = MediaItemType.Unknown;

        public MediaItemType Type
        {
            get { return (this._Type); }
            set
            {
                if (this._Type != value)
                {
                    this._Type = value;
                    FirePropertyChanged("Type");
                }
            }
        }

        private IMediaPlugin _Plugin;

        private Single _AvgRating = 0;

        public virtual Single AvgRating
        {
            get
            {
                return _AvgRating;
            }
            set
            {
                if (_AvgRating != value)
                {
                    _AvgRating = value;
                    FirePropertyChanged("AvgRating");
                }
            }
        }

        private Single _UserRating = 0;

        public virtual Single UserRating
        {
            get
            {
                return _UserRating;
            }
            set
            {
                if (_UserRating != value)
                {
                    _UserRating = value;
                    FirePropertyChanged("UserRating");
                }
            }
        }
        public IMediaPlugin Plugin
        {
            get { return (this._Plugin); }
            set 
            {
                if (this._Plugin != value)
                {
                    this._Plugin = value;
                    FirePropertyChanged("Plugin");
                }
            }
        }

        private string _ListDisplayName;

        public virtual string ListDisplayName
        {
            get
            {
                if (string.IsNullOrEmpty(_ListDisplayName))
                {
                    return Name;
                }
                else
                    return _ListDisplayName;
            }
            set
            {
                if (_ListDisplayName != value)
                {
                    _ListDisplayName = value;
                    FirePropertyChanged("ListDisplayName");
                }
            }
        }

        public virtual string ListDisplayDescription
        {
            get { return Description;  }
        }

        public virtual string ListDisplayProperties
        {
            get { return ""; }
        }

        protected ArrayListDataSet _Commands;

        public virtual ArrayListDataSet Commands
        {
            get { return (this._Commands); }
            set 
            {
                if (this._Commands != value)
                {
                    this._Commands = value;
                    FirePropertyChanged("Commands");
                }
            }
        }

        private IList _RatingsCommands;

        public virtual ArrayListDataSet RatingsCommands
        {
            get
            {
                if (_RatingsCommands == null)
                {
                    _RatingsCommands = new ArrayListDataSet(this);
                    for (int i = 1; i <= Plugin.RatingsScale; i++)
                    {
                        _RatingsCommands.Add(Plugin.CreateRatingsCommand(this, i));
                    }
                }
                return (ArrayListDataSet)_RatingsCommands;
            }
            set
            {
                if (_RatingsCommands != value)
                {
                    _RatingsCommands = value;
                    FirePropertyChanged("RatingsCommands");
                }
            }
        }
    }
}
